home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / mosmllib / test / macpath.sml < prev    next >
Encoding:
Text File  |  1997-08-18  |  16.7 KB  |  402 lines  |  [TEXT/R*ch]

  1. (* test/macpath.sml 6 -- for Unix, 1995-05-23 *)
  2.  
  3. (* Mac: changed "/" to ":"; isAbs changed appropriately
  4.         lots of other changes              -- 17Sep95 e
  5.         made "a" canonical instead of ":a" -- 17Jul96 e *)
  6.  
  7. use "auxil.sml";
  8.  
  9. local 
  10.     open Path
  11. in
  12.     
  13. val test1a = 
  14.     check'(fn _ => fromString "" = {isAbs=true, vol = "", arcs = []});
  15. val test1b = 
  16.     check'(fn _ => fromString ":" = {isAbs=false, vol="", arcs=[""]});
  17. val test1c = 
  18.     check'(fn _ => fromString "::" = {isAbs=false, vol="", arcs=["", ""]});
  19. val test1d = 
  20.     check'(fn _ => fromString "a" = {isAbs=false, vol = "", arcs = ["a"]});
  21. val test1e = 
  22.     check'(fn _ => fromString ":a" = {isAbs=false, vol="", arcs=["a"]});
  23. val test1f = 
  24.     check'(fn _ => fromString "::a" = {isAbs=false, vol="", arcs=["","a"]});
  25. val test1g = 
  26.     check'(fn _ => fromString "a:" = {isAbs=true, vol = "", arcs = ["a", ""]});
  27. val test1h = 
  28.     check'(fn _ => fromString "a::" = {isAbs=true, vol = "", arcs = ["a", "", ""]});
  29. val test1i = 
  30.     check'(fn _ => fromString "a:b" = {isAbs=true, vol = "", arcs = ["a", "b"]});
  31. val test1j = 
  32.     check'(fn _ => fromString "a.b:c" = {isAbs=true, vol = "", arcs = ["a.b", "c"]});
  33. val test1k = 
  34.     check'(fn _ => fromString "a.b:c:" = {isAbs=true, vol = "", arcs = ["a.b", "c", ""]});
  35. val test1l = 
  36.     check'(fn _ => fromString "a:.:c" = {isAbs=true, vol = "", arcs = ["a", ".", "c"]});
  37. val test1m = 
  38.     check'(fn _ => fromString "a:..:c" = {isAbs=true, vol = "", arcs = ["a", "..", "c"]});
  39. val test1n = 
  40.     check'(fn _ => fromString "." = {isAbs=false, vol = "", arcs = ["."]});
  41.  
  42. val test2a =
  43.     check'(fn _ => toString {isAbs=true, vol="", arcs = []} = "");
  44. val test2b = 
  45.     check'(fn _ => toString {isAbs=false, vol="", arcs=[]} = ":");
  46. val test2b' = 
  47.     check'(fn _ => toString {isAbs=false, vol="", arcs=[""]} = ":");
  48. val test2c = 
  49.     check'(fn _ => toString {isAbs=false, vol="", arcs=["",""]} = "::");
  50. val test2d = 
  51.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a"]} = "a");
  52. val test2e = 
  53.     check'(fn _ => toString {isAbs=false, vol="", arcs=["a"]} = "a");
  54. val test2f = 
  55.     check'(fn _ => toString {isAbs=false, vol="", arcs=["","a"]} = "::a");
  56. val test2g = 
  57.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", ""]} = "a:");
  58. val test2h = 
  59.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", "", ""]} = "a::");
  60. val test2i = 
  61.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", "b"]} = "a:b");
  62. val test2j = 
  63.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a.b", "c"]} = "a.b:c");
  64. val test2k = 
  65.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a.b", "c", ""]} = "a.b:c:");
  66. val test2l = 
  67.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", ".", "c"]} = "a:.:c");
  68. val test2m = 
  69.     check'(fn _ => toString {isAbs=true, vol = "", arcs = ["a", "..", "c"]} = "a:..:c");
  70. val test2n = 
  71.     check'(fn _ => toString {isAbs=false, vol="", arcs=["a", "..", "c"]} = ":a:..:c");
  72. val test2o = (toString {isAbs=true, vol = "foo", arcs =  ["", "a"]} seq "WRONG")
  73.              handle Path => "OK" | _ => "WRONG";
  74. val test2p = 
  75.     (toString {isAbs=true, vol = "C:", arcs =  ["windows"]} seq "WRONG")
  76.     handle Path => "OK" | _ => "WRONG";
  77.  
  78. val test3b = 
  79.     check'(fn _ => getVolume ":" = "");
  80. val test3c = 
  81.     check'(fn _ => getVolume "::" = "");
  82. val test3d = 
  83.     check'(fn _ => getVolume "a::b:c:" = "");
  84. val test3e = 
  85.     check'(fn _ => getVolume ".:" = "");
  86. val test3f = 
  87.     check'(fn _ => getVolume "..:" = "");
  88. val test3g = 
  89.     check'(fn _ => getVolume "" = "");
  90. val test3h = 
  91.     check'(fn _ => getVolume "C:" = "");
  92.  
  93. val test4a = 
  94.     check'(fn _ => 
  95.            not (List.all isRelative ["", ".", "..", "a::"])
  96.            andalso List.exists isRelative [":", ":a", "::"]);
  97. val test4b = 
  98.     check'(fn _ => 
  99.            not (List.all isAbsolute [":", ":a", "::", ":.", ":.."])
  100.            andalso List.exists isAbsolute ["", ".", "..", "a::"]);
  101.  
  102. val test5a = 
  103.     check'(fn _ => 
  104.            getParent ":" = "::"
  105.            andalso getParent "a" = ":"
  106.            andalso getParent "a:" = ""
  107.            andalso getParent ":a" = ":"
  108.            andalso getParent ":a:" = ":"
  109.            andalso getParent "a:::" = "a::::"
  110.            andalso getParent "a:b" = "a:"
  111.            andalso getParent "a:b:" = "a:"
  112.            andalso getParent ":a:b" = ":a:"
  113.            andalso getParent ":a:b:" = ":a:"
  114.            andalso getParent ":a::b:" = ":a::" (* not canonical, but input wasn't either *)
  115.            andalso getParent "::" = ":::"
  116.            andalso getParent ":::" = "::::"
  117.            andalso getParent "" = "");
  118.  
  119. val test6a = 
  120.     check'(fn _ => 
  121.            concat("a", "b") = ":a:b"
  122.            andalso concat("a", ":b:c") = ":a:b:c"
  123.            andalso concat(":", ":b:c") = ":b:c"
  124.            andalso concat("", ":b:c") = "b:c"
  125.            andalso concat(":a", ":b:c") = ":a:b:c"
  126.            andalso concat("a:", ":b:c") = "a:b:c"
  127.            andalso concat("a::", ":b:c") = "a::b:c"
  128.            andalso concat("a:b", "::") = "a:b::"
  129.            andalso concat("a:b", "::c") = "a:b::c");
  130. val test6b = (concat ("a", "b:") seq "WRONG")
  131.              handle Path => "OK" | _ => "WRONG";
  132.  
  133. val test7a = 
  134.     check'(fn _ => 
  135.            mkAbsolute("a:b", "c:d") = "a:b"
  136.            andalso mkAbsolute("", "c:d") = ""
  137.            andalso mkAbsolute(":a:b", "c:d") = "c:d:a:b");
  138. val test7b = (mkAbsolute("a:", ":c:d") seq "WRONG")
  139.              handle Path => "OK" | _ => "WRONG";
  140. val test7c = (mkAbsolute(":a", ":c:d") seq "WRONG")
  141.               handle Path => "OK" | _ => "WRONG";
  142.  
  143. val test8a = 
  144.     check'(fn _ => 
  145.                    mkRelative(":a:b", "c:d")     = ":a:b"
  146.            andalso mkRelative("", "a:b:c")       = "::::"
  147.            andalso mkRelative("a:", "a:b:c")     = ":::"
  148.            andalso mkRelative("a:b", "a:c")      = "::b"
  149.            andalso mkRelative("a:b", "a:c:")     = "::b"
  150.            andalso mkRelative("a:b:", "a:c")     = "::b:"
  151.            andalso mkRelative("a:b:", "a:c:")    = "::b:"
  152.            andalso mkRelative(":", "")           = ":"
  153.            andalso mkRelative("", "")            = ":"
  154.            andalso mkRelative("", "a:")          = "::"
  155.            andalso mkRelative("a:b::c", "a:d")   = "::b::c"
  156.            andalso mkRelative("a:b", "c:d")      = ":::a:b"
  157.            andalso mkRelative("c:a:b", "c:d")    = "::a:b"
  158.            andalso mkRelative("c:d:a:b", "c:d")  = ":a:b"
  159.            andalso mkRelative("c:d:a:b:", "c:d") = ":a:b:"
  160.            andalso mkRelative("c:d:a:b:", "c:d:")= ":a:b:"
  161.            andalso mkRelative("a:b:", "a:b:")    = ":"
  162.            andalso mkRelative("a:b:", "a:b:c:")  = "::"
  163.            andalso mkRelative("a:b:", "a:b:c:d:")= ":::"
  164.            andalso mkRelative("a:b:", "a:b")     = ":"
  165.            andalso mkRelative("a:b:", "a:b:c")   = "::"
  166.            andalso mkRelative("a:b:", "a:b:c:d") = ":::"
  167.            andalso mkRelative("a:b", "a:b:")     = ":"
  168.            andalso mkRelative("a:b", "a:b:c:")   = "::"
  169.            andalso mkRelative("a:b", "a:b:c:d:") = ":::"
  170.            andalso mkRelative("a:b", "a:b")      = ":"
  171.            andalso mkRelative("a:b", "a:b:c")    = "::"
  172.            andalso mkRelative("a:b", "a:b:c:d")  = ":::"
  173.            );
  174. val test8b = (mkRelative("a:", ":c:d") seq "WRONG")
  175.               handle Path => "OK" | _ => "WRONG";
  176. val test8c = (mkRelative(":a", ":c:d") seq "WRONG")
  177.               handle Path => "OK" | _ => "WRONG";
  178.  
  179.  
  180. val test9a = let
  181.     fun chkCanon (a, b) =
  182.           (mkCanonical a = b) 
  183.           andalso (mkCanonical b = b)
  184.           andalso (isCanonical b)
  185.     in
  186.       check'(fn _ => 
  187.            chkCanon("", "")
  188.            andalso chkCanon(":", ":")
  189.            andalso chkCanon("::", "::")
  190.            andalso chkCanon(":::", ":::")
  191.            andalso chkCanon("b", "b")
  192.            andalso chkCanon("a:b", "a:b")
  193.            andalso chkCanon(":a:b", ":a:b")
  194.            andalso chkCanon("a:b:", "a:b:")
  195.            andalso chkCanon("a:b::", "a:")
  196.            andalso chkCanon(":a:::b", "::b")
  197.            andalso chkCanon(":a::", ":")
  198.            andalso chkCanon("a::", "")
  199.            andalso chkCanon("a:", "a:")
  200.            andalso chkCanon(":a::b:", ":b:")
  201.            andalso chkCanon("x:::a:b", "a:b")
  202.            andalso chkCanon("x::", "")
  203.            andalso chkCanon("a::b", "b")           (* Mac problem!? *)
  204.            andalso chkCanon("a::b:", "b:")
  205.            )
  206.     end;
  207.  
  208. val test9b = check'(fn _ => 
  209.                   mkCanonical "" = ""
  210.                   andalso mkCanonical ":" = ":"
  211.                   andalso mkCanonical "::" = "::"
  212.                   andalso mkCanonical ":::" = ":::"
  213.                   andalso mkCanonical "a" = "a"
  214.                   andalso mkCanonical "a:" = "a:"
  215.                   andalso mkCanonical ":a" = "a"    (* Mac feature *)
  216.                   andalso mkCanonical ":a:" = ":a:"
  217.                   andalso mkCanonical "a::b" = "b"
  218.                   andalso mkCanonical "a::b:" = "b:"
  219.                   andalso mkCanonical ":a::b" = "b"
  220.                   andalso mkCanonical ":a::b:" = ":b:"
  221.                   andalso mkCanonical ":a::" = ":"
  222.                   andalso mkCanonical ":a::b::c" = "c"
  223.                   andalso mkCanonical "a::b::c:" = "c:"
  224.                   andalso mkCanonical "a::b::c" = "c"
  225.                   andalso mkCanonical "a:b:c:::d" = "a:d"
  226.                   andalso mkCanonical ":a:b:c:::d" = ":a:d"
  227.                   andalso mkCanonical "a:b:c::::d" = "d"
  228.                   andalso mkCanonical ":a:b:c::::d" = "d"
  229.                   andalso mkCanonical ":a:b:c:::::d" = "::d"
  230.                   andalso mkCanonical "a:b:c:::d:" = "a:d:"
  231.                   andalso mkCanonical ":a:b:c:::d:" = ":a:d:"
  232.                   andalso mkCanonical "a:b:c::::d:" = "d:"
  233.                   andalso mkCanonical ":a:b:c::::d:" = ":d:"
  234.                   andalso mkCanonical ":a:b:c:::::d:" = "::d:"
  235.                   );
  236.  
  237. val test10a = 
  238.     check'(fn _ => 
  239.            isCanonical ":"
  240.            andalso isCanonical "::"
  241.            andalso isCanonical ""
  242.            andalso isCanonical "a"
  243.            andalso isCanonical "a:"
  244.            andalso isCanonical "a:b"
  245.            andalso isCanonical "a:b:"
  246.            andalso isCanonical ":a:b"
  247.            andalso isCanonical ":a:b:");
  248.  
  249.                 
  250. val test10b = 
  251.     check'(fn _ => 
  252.            not (isCanonical ":x::"
  253.                 orelse isCanonical "x::"
  254.                 orelse isCanonical "a::"
  255.                 orelse isCanonical ":a::b"
  256.                 orelse isCanonical ":a::"
  257.                 orelse isCanonical ":a:::"));
  258.  
  259. val test10c = check'(fn _ => isCanonical "b");
  260.  
  261. val test11a = 
  262.     check'(fn _ => 
  263.            splitDirFile "" = {dir = "", file = ""}
  264.            andalso splitDirFile "." = {dir = "", file = "."}
  265.            andalso splitDirFile ".." = {dir = "", file = ".."}
  266.            andalso splitDirFile "b" = {dir = "", file = "b"}
  267.            andalso splitDirFile "b:" = {dir = "b:", file = ""}
  268.            andalso splitDirFile "a:b" = {dir = "a:", file = "b"}
  269.            andalso splitDirFile ":a" = {dir = "", file = "a"}
  270.            andalso splitDirFile ":a:b" = {dir = ":a:", file = "b"}
  271.            andalso splitDirFile ":c:a:b" = {dir = ":c:a:", file = "b"}
  272.            andalso splitDirFile ":c:a:b:" = {dir = ":c:a:b:", file = ""}
  273.            andalso splitDirFile ":c:a:b.foo.bar" = {dir = ":c:a:", file="b.foo.bar"}
  274.            andalso splitDirFile ":c:a:b.foo" = {dir = ":c:a:", file = "b.foo"});
  275.  
  276. (*    
  277. val test11b = (splitDirFile "" seq "WRONG") 
  278.               handle Path => "OK" | _ => "WRONG";
  279. *)
  280. val test11b = (splitDirFile "" seq splitDirFile ":" seq "DIFFERENT");
  281.  
  282. val test12 = 
  283.     check'(fn _ => 
  284.            "" = joinDirFile {dir = "", file = ""}
  285.            andalso "b" = joinDirFile {dir = "", file = "b"}
  286.            andalso ":" = joinDirFile {dir = ":", file = ""}
  287.            andalso ":b" = joinDirFile {dir = ":", file = "b"}
  288.            andalso "a:b" = joinDirFile {dir = "a:", file = "b"}
  289.            andalso ":a:b" = joinDirFile {dir = ":a", file = "b"}
  290.            andalso ":c:a:b" = joinDirFile {dir = ":c:a", file = "b"}
  291.            andalso ":c:a:b:" = joinDirFile {dir = ":c:a:b", file = ""}
  292.            andalso ":c:a:b.foo.bar" = joinDirFile {dir = ":c:a", file="b.foo.bar"}
  293.            andalso ":c:a:b.foo" = joinDirFile {dir = ":c:a", file = "b.foo"});
  294.  
  295. val test13 = 
  296.     check'(fn _ => 
  297.            dir "b" = ""                   (* not ":" anymore *)
  298.            andalso dir "a:" = "a:"
  299.            andalso dir "a:b" = "a:"
  300.            andalso dir ":" = ":"
  301.            andalso dir ":b" = ""          (* not ":" anymore *)
  302.            andalso dir ":a:b" = ":a:"
  303.            andalso dir ":c:a:b" = ":c:a:"
  304.            andalso dir ":c:a:b:" = ":c:a:b:"
  305.            andalso dir ":c:a:b.foo.bar" = ":c:a:"
  306.            andalso dir ":c:a:b.foo" = ":c:a:");
  307.  
  308. val test14 = 
  309.     check'(fn _ => 
  310.            file "b" = "b"
  311.            andalso file "a:b" = "b"
  312.            andalso file ":" = ""
  313.            andalso file ":b" = "b"
  314.            andalso file ":a:b" = "b"
  315.            andalso file ":c:a:b" = "b"
  316.            andalso file ":c:a:b:" = ""
  317.            andalso file ":c:a:b.foo.bar" = "b.foo.bar"
  318.            andalso file ":c:a:b.foo" = "b.foo");
  319.  
  320. val test15 = 
  321.     check'(fn _ => 
  322.            splitBaseExt "" = {base = "", ext = NONE}
  323.            andalso splitBaseExt ".login" = {base = ".login", ext = NONE}
  324.            andalso splitBaseExt ":.login" = {base = ":.login", ext = NONE} (* weird? *)
  325.            andalso splitBaseExt "a" = {base = "a", ext = NONE}
  326.            andalso splitBaseExt "a." = {base = "a.", ext = NONE}
  327.            andalso splitBaseExt "a.b" = {base = "a", ext = SOME "b"}
  328.            andalso splitBaseExt "a.b.c" = {base = "a.b", ext = SOME "c"}
  329.            andalso splitBaseExt ":a.b" = {base = "a", ext = SOME "b"}
  330.            andalso splitBaseExt ":c:a.b" = {base = ":c:a", ext = SOME "b"}
  331.            andalso splitBaseExt ":c:a:b:.d" = {base = ":c:a:b:.d", ext = NONE}
  332.            andalso splitBaseExt ":c.a:b.d" = {base = ":c.a:b", ext = SOME "d"}
  333.            andalso splitBaseExt ":c.a:bd" = {base = ":c.a:bd", ext = NONE}
  334.            andalso splitBaseExt ":c:a:b.foo.bar" = {base=":c:a:b.foo",ext=SOME "bar"}
  335.            andalso splitBaseExt ":c:a:b.foo" = {base = ":c:a:b", ext = SOME "foo"});
  336.  
  337. val test16 = 
  338.     check'(fn _ => 
  339.            "" = joinBaseExt {base = "", ext = NONE}
  340.            andalso ".login" = joinBaseExt {base = ".login", ext = NONE}
  341.            andalso "a" = joinBaseExt {base = "a", ext = NONE}
  342.            andalso "a" = joinBaseExt {base = "a", ext = SOME ""}
  343.            andalso "a.b" = joinBaseExt {base = "a", ext = SOME "b"}
  344.            andalso "a.b.c" = joinBaseExt {base = "a.b", ext = SOME "c"}
  345.            andalso "a.b.c.d" = joinBaseExt {base = "a.b", ext = SOME "c.d"}
  346.            andalso ":a.b" = joinBaseExt {base = ":a", ext = SOME "b"}
  347.            andalso ":c:a.b" = joinBaseExt {base = ":c:a", ext = SOME "b"}
  348.            andalso ":c:a:b:.d" = joinBaseExt {base = ":c:a:b:", ext = SOME "d"}
  349.            andalso ":c:a:b.foo.bar" = joinBaseExt {base=":c:a:b",ext=SOME "foo.bar"}
  350.            andalso ":c:a:b.foo" = joinBaseExt {base = ":c:a:b", ext = SOME "foo"});
  351.  
  352. val test17 = 
  353.     check'(fn _ => 
  354.            ext "" = NONE
  355.            andalso ext ".login" = NONE
  356.            andalso ext ":.login" = NONE
  357.            andalso ext "a" = NONE
  358.            andalso ext "a." = NONE
  359.            andalso ext "a.b" = SOME "b"
  360.            andalso ext "a.b.c" = SOME "c"
  361.            andalso ext "a.b.c.d" = SOME "d"
  362.            andalso ext ":a.b" = SOME "b"
  363.            andalso ext ":c:a.b" = SOME "b"
  364.            andalso ext ":c:a:b:.d" = NONE
  365.            andalso ext ":c.a:b.d" = SOME "d"
  366.            andalso ext ":c.a:bd" = NONE
  367.            andalso ext ":c:a:b.foo.bar" = SOME "bar"
  368.            andalso ext ":c:a:b.foo" = SOME "foo");
  369.  
  370. val test18 = 
  371.     check'(fn _ => 
  372.            base "" = ""
  373.            andalso base ".d" = ".d"
  374.            andalso base ".login" = ".login"
  375.            andalso base ":.login" = ":.login"
  376.            andalso base "a" = "a"
  377.            andalso base "a." = "a."
  378.            andalso base "a.b" = "a"
  379.            andalso base "a.b.c" = "a.b"
  380.            andalso base "a.b.c.d" = "a.b.c"
  381.            andalso base "x:a.b" = "x:a"
  382.            andalso base "x:c:a.b" = "x:c:a"
  383.            andalso base "x:c:a:b:.d" = "x:c:a:b:.d"
  384.            andalso base ":a.b" = "a"
  385.            andalso base ":c:a.b" = ":c:a"
  386.            andalso base ":c:a:b:.d" = ":c:a:b:.d"
  387.            andalso base ":c.a:b.d" = ":c.a:b"
  388.            andalso base ":c.a:bd" = ":c.a:bd"
  389.            andalso base ":c:a:b.foo.bar" = ":c:a:b.foo"
  390.            andalso base ":c:a:b.foo" = ":c:a:b");
  391.  
  392. val test19 = 
  393.     check'(fn () => validVolume{isAbs=false, vol=""}
  394.            andalso validVolume{isAbs=true, vol=""}
  395.            andalso not (validVolume{isAbs=true, vol=":"}
  396.                         orelse validVolume{isAbs=false, vol=":"} 
  397.                         orelse validVolume{isAbs=true, vol="C:"}
  398.                         orelse validVolume{isAbs=false, vol="C:"}
  399.                         orelse validVolume{isAbs=true, vol=" "}
  400.                         orelse validVolume{isAbs=false, vol=" "})); 
  401. end
  402.